package com.pd.backend.service.impl;

import com.pd.backend.entity.PdTruck;
import com.pd.backend.dao.PdTruckDao;
import com.pd.backend.service.PdTruckService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 车辆信息表(PdTruck)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:36
 */
@Service("pdTruckService")
public class PdTruckServiceImpl implements PdTruckService {
    @Resource
    private PdTruckDao pdTruckDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdTruck queryById(String id) {
        return this.pdTruckDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdTruck     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdTruck> queryByPage(PdTruck pdTruck, PageRequest pageRequest) {
        long total = this.pdTruckDao.count(pdTruck);
        return new PageImpl<>(this.pdTruckDao.queryAllByLimit(pdTruck, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdTruck 实例对象
     * @return 实例对象
     */
    @Override
    public PdTruck insert(PdTruck pdTruck) {
        this.pdTruckDao.insert(pdTruck);
        return pdTruck;
    }

    /**
     * 修改数据
     *
     * @param pdTruck 实例对象
     * @return 实例对象
     */
    @Override
    public PdTruck update(PdTruck pdTruck) {
        this.pdTruckDao.update(pdTruck);
        return this.queryById(pdTruck.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdTruckDao.deleteById(id) > 0;
    }
}
